package com.qq.BFMRSE.BF_MRSEController;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.qq.BFMRSE.Cache.indexCache;
import com.qq.BFMRSE.Cache.indexCacheManager;
import com.qq.BFMRSE.util.BFConstants;
@Controller
public class handlerHello {
	@RequestMapping(value = "/welcome")
    public String registPost(HttpServletRequest request,HttpServletResponse response) {
    	WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
    	indexCacheManager instance=(indexCacheManager) wac.getBean("cacheInstance");
    	System.out.println(instance.getCacheSize());
    	if(instance.getCacheSize()==0){
    		indexCache cache1=new indexCache("cache1", "cache1", System.currentTimeMillis(), false);
    		indexCache cache2=new indexCache("cache2", "cache2", System.currentTimeMillis(), false);

    		indexCache cache3=new indexCache("cache3", "cache3", System.currentTimeMillis(), false);	

    		indexCache cache4=new indexCache("cache4", "cache4", System.currentTimeMillis(), false);
    		instance.addData2Cache("cache1", cache1);
    		instance.addData2Cache("cache2", cache2);
    		instance.addData2Cache("cache3", cache3);
    		instance.addData2Cache("cache4", cache4);
    	}

        return "hello";
    }  

}
